/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pigx.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.user.entity.UserApiLockDuration;
import com.pig4cloud.pigx.user.service.UserApiLockDurationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Api封禁时长配置表
 *
 * @since 2022-10-31 15:36:06
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/userapilockduration")
@Api(value = "userapilockduration", tags = "Api封禁时长配置表管理")
public class UserApiLockDurationController {

	private final UserApiLockDurationService userApiLockDurationService;

	/**
	 * 分页查询
	 *
	 * @param page      分页条件
	 * @param condition 查询条件
	 * @return {@link R< Page< UserApiLockDuration>>}
	 * @since 2022/10/31 15:47
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	// @PreAuthorize("@pms.hasPermission('user_api_config_view')")
	@GetMapping("/page")
	public R<Page<UserApiLockDuration>> page(Page<UserApiLockDuration> page, UserApiLockDuration condition) {
		return R.ok(userApiLockDurationService.page(page, condition));
	}

	/**
	 * 根据id查询详情
	 *
	 * @param id id
	 * @return {@link R< UserApiLockDuration>}
	 * @since 2022/10/31 15:49
	 */
	@ApiOperation(value = "根据id查询详情", notes = "根据id查询详情")
	// @PreAuthorize("@pms.hasPermission('user_api_config_view')")
	@GetMapping("/{id}")
	public R<UserApiLockDuration> detail(@PathVariable("id") Long id) {
		return R.ok(userApiLockDurationService.detail(id));
	}

	/**
	 * 新增
	 *
	 * @param param 参数
	 * @return {@link R< Boolean>}
	 * @since 2022/10/31 16:18
	 */
	@ApiOperation(value = "新增", notes = "新增")
	@SysLog("新增Api封禁时长配置表")
	// @PreAuthorize("@pms.hasPermission('user_api_config_add')")
	@PostMapping
	public R<Boolean> insert(@RequestBody UserApiLockDuration param) {
		userApiLockDurationService.insert(param);
		return R.ok();
	}

	/**
	 * 修改
	 *
	 * @param param 参数
	 * @return {@link R< Boolean>}
	 * @since 2022/10/31 16:31
	 */
	@ApiOperation(value = "修改", notes = "修改")
	@SysLog("修改Api封禁时长配置表")
	// @PreAuthorize("@pms.hasPermission('user_api_config_edit')")
	@PutMapping
	public R<Boolean> update(@RequestBody UserApiLockDuration param) {
		userApiLockDurationService.update(param);
		return R.ok();
	}

	/**
	 * 根据id删除
	 *
	 * @param id id
	 * @return {@link R< Boolean>}
	 * @since 2022/10/31 16:43
	 */
	@ApiOperation(value = "根据id删除", notes = "根据id删除")
	@SysLog("通过id删除Api封禁时长配置表")
	// @PreAuthorize("@pms.hasPermission('user_api_config_del')")
	@DeleteMapping("/{id}")
	public R<Boolean> remove(@PathVariable Long id) {
		userApiLockDurationService.remove(id);
		return R.ok();
	}
}
